package cn.xjt.Utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

import java.text.SimpleDateFormat;

/**
 * 内容：
 *
 * @author
 * @date 2020/9/22-15:24
 */
public class JsonUtils {

	public static String getJson(Object object)
	{
		String json = getJson(object, "yyyy-MM-dd HH:mm:ss");
		return json;
	}

	public static String getJson(Object object,String dateformat)
	{
		ObjectMapper mapper = new ObjectMapper();

		mapper.configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS,false);

		SimpleDateFormat sd = new SimpleDateFormat(dateformat);

		mapper.setDateFormat(sd);

		try {
			return mapper.writeValueAsString(object);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return "返回出现了异常";
	}
}
